<?php
	  //声明文件解析的编码格式
	 header('content-type:text/html;charset=utf-8');
	 // 本文件是取新闻页的数据
	 require('function.php');
	 //1.连接数据库
	 $conn=dbcon();
	 //2.写sql语句

	 //3.取新闻的类型到$newstype数组
	 $sql='select * from sente_type';
	 $result = $conn->query($sql);
	 if ($result->num_rows>0)  //执行的结果集有多少条记录
     {
     	$newstype=array();
     	while($row = $result->fetch_assoc())
     	{
     		$newstype[]=$row;
     	}
     }

     //4.取新闻到$news数组
     //如果地址栏没有typeid，新闻显示所有     
     //如果地址栏有typeid
     $typeId = isset($_GET['typeId']) ? $_GET['typeId'] : '';
     if ($typeId=='')
     {
     	$sql='select a.*,b.typename from sente_news a,sente_type b where a.typeId=b.typeId  order by newsDate desc';
     }
     else
     {
     	$sql="select a.*,b.typename from sente_news a,sente_type b where a.typeId=b.typeId and b.typeId=$typeId order by newsDate desc";
     }
	 $result = $conn->query($sql);
	 if ($result->num_rows>0)  //执行的结果集有多少条记录
     {
     	$news=array();
     	while($row = $result->fetch_assoc())
     	{
     		$news[]=$row;
     	}
     }

     //加载显示新闻的html模板
     require('news_html.php');


     ?>
